<?php

namespace App\Containers\AppSection\Signature\UI\API\Transformers;

use App\Containers\AppSection\File\UI\API\Transformers\FileTransformer;
use App\Containers\AppSection\Profile\UI\API\Transformers\ProfileTransformer;
use App\Containers\AppSection\Signature\Models\Signature;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Item;

class SignatureTransformer extends Transformer
{
    /**
     * @var  array
     */
    protected array $defaultIncludes = [

    ];

    /**
     * @var  array
     */
    protected array $availableIncludes = [
        'file',
        'profile'
    ];

    public function transform(Signature $signature): array
    {
        return [
            'object' => $signature->getResourceKey(),
            'id' => $signature->getHashedKey(),
            'issuer' => $signature->issuer,
            'subject' => $signature->subject,
            'signing_time' => $this->dateFormatter($signature->signing_time),
            'version' => $signature->version,
            'serial_number' => $signature->serial_number,
            'valid_from' => $this->dateTimeFormatter($signature->valid_from),
            'valid_to' => $this->dateTimeFormatter($signature->valid_to),
            'is_private' => $signature->is_private,
            'is_valid' => $signature->is_valid,
            'created_at' => $this->dateFormatter($signature->created_at),
            'updated_at' => $this->dateFormatter($signature->updated_at),
            'readable_created_at' => $signature->created_at->diffForHumans(),
            'readable_updated_at' => $signature->updated_at->diffForHumans(),
        ];
    }

    public function includeFile(Signature $t): Item
    {
        return $this->item($t->file, new FileTransformer);
    }

    public function includeProfile(Signature $t): Item
    {
        return $this->item($t->profile, new ProfileTransformer);
    }
}
